package rocky.freemanagementsystemserver.service

import org.springframework.stereotype.Service
import org.springframework.beans.factory.annotation.Autowired
import rocky.freemanagementsystemserver.Entity.User
import rocky.freemanagementsystemserver.projection.UserInfo
import rocky.freemanagementsystemserver.service.interfaces.IUserService
import rocky.freemanagementsystemserver.repository.UserRepository


@Service
class UserService : IUserService {

    @Autowired
    private lateinit var userRepository: UserRepository;

    override fun addUser(user: User) {
        userRepository.save(user)
    }

    override fun getUsers(): List<User> {
        return userRepository.findAll();
    }

    override fun deleteUser(id: String): Unit {
        return userRepository.deleteById(id);
    }

    override fun getUserByName(name: String): User {
        return userRepository.findByNameEqualsIgnoreCase(name);
    }

}